package org.projeto.thirdhood.controller;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.projeto.thirdhood.beans.Pet;
import org.projeto.thirdhood.model.PetDAOFake;



@Path("/pet")
public class PetResource {

	
	//Dados Fake
	
	PetDAOFake dao = new PetDAOFake();
	
	@GET
	@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public List<Pet> findAll() {
		System.out.println("findAll");
		return dao.findAll();
	}

	@GET @Path("search/{query}")
	@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public List<Pet> findByName(@PathParam("query") String query) {
		System.out.println("findByName: " + query);
		return dao.findByName(query);
	}

	@GET @Path("{codPet}")
	@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public Pet findById(@PathParam("codPet") String codPet) {
		System.out.println("findById " + codPet);
		return dao.findById(Integer.parseInt(codPet));
	}

	@POST
	@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
	@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public Pet create(Pet pet) {
		System.out.println("creating pet");
		return dao.create(pet);
	}

	@PUT @Path("{codPet}")
	@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
	@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public Pet update(Pet pet) {
		System.out.println("Updating pet: " + pet.getDescPet());
		dao.update(pet);
		return pet;
	}
	
	@DELETE @Path("{codPet}")
	@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public void remove(@PathParam("codPet") int codPet) {
		dao.remove(codPet);
	}

}
